<?php
namespace app\common\service\home;


use app\admin\model\deploy\HomeCarousel;
use app\admin\model\deploy\QuickEntry;
use app\common\service\BaseService;
use think\facade\Cache;

class HomeService extends BaseService
{


    /**
     * Author:Yingbo Sun
     *
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getQuickEntry()
    {
        $redis = Cache::store('redis');
        $redis->select(15);
        $bool = $redis->has('home:QuickEntry');
        if ($bool){
            $data = $redis->get('home:QuickEntry');
        }else{
            $data = QuickEntry::select()->toArray();
            $redis->set('home:QuickEntry',$data);
        }
        return self::success('获取成功',$data);
    }


    public static function getCarousel()
    {
        $redis = Cache::store('redis');
        $redis->select(15);
        $bool = $redis->has('home:Carousel');
        if ($bool){
            $data = $redis->get('home:Carousel');
        }else{
            $data = HomeCarousel::order('sort','desc')
                ->field(['home_carousel','home_route','create_time'])
                ->limit(config('setting.home_image'))->select()->toArray();
            $redis->set('homeCarousel',$data);
        }
        return self::success('获取成功',$data);
    }
}
